
	function addPhotoPreview (imgs, url) {
        var max = parseInt(imgs.attr('data-max-length'));
        if (max < imgs.find('.img-box').length) {
            imgs.find('.img-box').eq(max - 1).css('background-image', 'url(' + url + ')').find('input[type=hidden]').val(url);
        } else {
            imgs.find('.img-box:last-child').css('background-image', 'url(' + url + ')').find('input[type=hidden]').val(url);
            var index = parseInt(imgs.attr('data-index'));
            index++;
            var html = '<div class="img-box"><b class="close"><img src="../images/icon-fork-white.png" alt=""></b><input type="file" id="img' + (index) + '"><input type="hidden"></div>';

            imgs.attr('data-index', index).append(html);
        }
    }


    function checkIdNumber(code){
        var code = code.value;
        var city={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江 ",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北 ",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏 ",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外 "};
        var tip = "";
        var pass= true;
        
        // if(!code || !/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[12])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i.test(code)){
            //tip = "身份证号格式错误";
            //pass = false;
        //}
        
      	if(!city[code.substr(0,2)]){
            tip = "身份证号格式错误";
            pass = false;
        }
        //else{
            //18位身份证需要验证最后一位校验位
            /*if(code.length == 18){
                code = code.split('');
                //∑(ai×Wi)(mod 11)
                //加权因子
                var factor = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ];
                //校验位
                var parity = [ 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 ];
                var sum = 0;
                var ai = 0;
                var wi = 0;
                for (var i = 0; i < 17; i++)
                {
                    ai = code[i];
                    wi = factor[i];
                    sum += ai * wi;
                }
                var last = parity[sum % 11];
                if(parity[sum % 11] != code[17]){
                    tip = "校验位错误";
                    pass =false;
                }
            }
            */
        //}
        
        //if(!pass) alert(tip);
        isIdNumVailded = pass;
        return pass;
    }

    function checkPhoneNumber(value){
    	var mobile = value.value 
        if(!(/^1[3|4|5|7|8][0-9]\d{8}$/.test(mobile))){ 
            //alert("手机号格式错误");
            isPhoneNumVailded = false;
            return false; 
        }else{
        	isPhoneNumVailded = true;
            return true;
        } 
    }

    function checkBankNumber(value){
    	var mobile = value.value 
        if(!(/^\d{12}|\d{20}$/.test(mobile))){ 
            //alert("银行账号格式错误");
            isBankNumberVailded = false;
            return false; 
        }else{
        	isBankNumberVailded = true;
            return true;
        } 
    }


    function checkAuthCode(){
        var mobile = $("#mobile").val();
    	var value = $("#authCode").val();
    	$.ajax({
			url:"/scfire/user/authCode",
			type:'POST',
			data:{
				  "code":value,
				  "mobile":mobile
				  },
			dataType:'text',
			async: false,
			contentType: "application/x-www-form-urlencoded; charset=utf-8",
			success:function(data){
				var result = JSON.parse(data).info.text;
				var code = JSON.parse(data).code;
				if(code=="200"){
				//	alert(result);
					authCodeStats = true;
				}else{
					alert('验证码校验失败！');
					authCodeStats = false;
				}				
			},
			error: function (data){
				alert('验证码校验失败！');
				authCodeStats = false;
			}
		}); 
    }

    function isMobileExist(mobile){
    	$.ajax({
			url:"/scfire/user/mobileExist",
			type:'POST',
			data:{
				  "mobile":mobile
				  },
			dataType:'text',
			async: false,
			contentType: "application/x-www-form-urlencoded; charset=utf-8",
			success:function(data){
				var result = JSON.parse(data).info.text;
				var code = JSON.parse(data).code;
				if(code=="200"){
					//alert(result);
				}else{
					alert(result);
				}				
			},
			error: function (data){
				//
			}
		});
    }

    function isIDNumExist(idNum){
    	$.ajax({
			url:"/scfire/user/idExist",
			type:'POST',
			data:{
				  "idNum":idNum
				  },
			dataType:'text',
			async: false,
			contentType: "application/x-www-form-urlencoded; charset=utf-8",
			success:function(data){
				var result = JSON.parse(data).info.text;
				var code = JSON.parse(data).code;
				if(code=="200"){
					//alert(result);
				}else{
					alert(result);
				}				
			},
			error: function (data){
				//
			}
		});
    }
    
    function sendSMS(mobile){

        if(!isPhoneNumVailded){
        	alert("号码格式不正确，短信发送失败.");
        	return false;
        }
    	$.ajax({
			url:"/scfire/SmsVerification/sendSmsVerification",
			type:'POST',
			data:{
				  "mobile":mobile
				  },
			dataType:'text',
			async: false,
			contentType: "application/x-www-form-urlencoded; charset=utf-8",
			success:function(data){
				var result = JSON.parse(data).info.text;
				if(data.code=="200"){
					alert('短信发送成功.');
				}else{
				//	alert(result);
				}				
			},
			error: function (data){
				alert("短信发送失败.请稍后再试");
			}
		});
    	return true;
    }

    function checkIdInfo(){
    	var realName = $("#realName").val();
    	var idNumber = $("#idNumber").val();
    	var school = $("#school").val();
    	var description = $("#description").val();
    	var identifyimg = $("#identifyimg").val();
    	var identifyimgre = $("#identifyimgre").val();
    	
    	var vailedFlag = true;
    	
    	
    	if(!nullErrorAlert(idNumber, "请填写身份证号！")){
    		return false;
        }
        if(!isIdNumVailded){
    		alert("请先核对您的身份证号是否填写有误！");
    		return false;
        }
        
    	if(!nullErrorAlert(realName, "请填写您的姓名！")){
    		return false;
        }
    	if(!nullErrorAlert(school, "机构名不能为空！")){
    		return false;
        }
    	if(!nullErrorAlert(description, "请填写您的简介！")){
    		return false;
        }
    	if(description.length>800){
    		alert("简介最大800字！");
    		return false;
    	}
    	if(!nullErrorAlert(identifyimg, "请上传您的身份证正面照！")){
    		return false;
        }
        
        if(!nullErrorAlert(identifyimgre, "请上传您的身份证反面照！")){
    		return false;
        }

        return true;
    }

    function nullErrorAlert(checkStr, infoStr){
    	if(checkStr == ""){
    		alert(infoStr);
    		return false;
    	}
    	return true;
    }
    function checkBankInfo(){
    	var bankCard = $("#bankCard").val();
    	var bankName = $("#bankName").find("option:selected").text();
    	var s_province = $("#s_province").val();
    	var s_city = $("#s_city").val();
    	
    	
    	var vailedFlag = true;
    	
    	vailedFlag = nullErrorAlert(bankCard, "请填写银行卡号！");
    	if(!vailedFlag){
    		return false;
        }
        if(!isBankNumberVailded){
    		alert("请先核对您的银行账号是否填写有误！");
    		return false;
        }
        
        if(bankName == '选择开户行' || bankName == ''){
        	alert("请选择开户银行！");
        	vailedFlag = false;
        }
        
        if(s_province == '省份' || s_province == ''){
        	alert("请选择开户省份！");
        	return false;
        }
        if(s_city == '地级市' || s_city == ''){
        	alert("请选择开户地级市！");
        	return false;
        }
    	
    	if(!vailedFlag){
    		return false;
        }else{
        	
        	
        	return true;
        }
    }
    
    function submitAuthInfo(){
        
    	var realName = $("#realName").val();
    	var idNumber = $("#idNumber").val();
    	var mobile = $("#mobile").val();
    	var bankCard = $("#bankCard").val();
    	var bankName = $("#bankName").find("option:selected").text();
    	var school = $("#school").val();
    	var subBranch = $("#s_province").val()+"_"+$("#s_city").val()+"_"+$("#subBranch").val();
    	var description = $("#description").val();
    	var identifyimg = $("#identifyimg").val();
    	var identifyimgre = $("#identifyimgre").val();

    	if(!isIdNumVailded){
    		alert("请先核对您的身份证号是否填写有误！");
    		return;
        }
    	if(!isPhoneNumVailded){
    		alert("请先核对您的手机号是否填写有误！");
    		return;
        }
    	if(!isBankNumberVailded){
    		alert("请先核对您的银行账号是否填写有误！");
    		return;
        }
        //简介不能为空
    	if(description.replace(/(^\s*)|(\s*$)/g, "").length ==0){
    		alert("请填写您的个人简介！");
    		return;
        }
        //先校验验证码
        checkAuthCode();
        if(!authCodeStats){
        	alert("请填写正确的验证码！");
    		return;
        }

    
    	$.ajax({
			url:"/scfire/user/userAuthSubmit",
			type:'POST',
			data:{"realName":realName,
				  "idNumber":idNumber,
				  "identifyimg":identifyimg,
				  "identifyimgre":identifyimgre,
				  "subBranch":subBranch,
				  "mobile":mobile,
				  "bankCard":bankCard,
				  "bankName":bankName,
				  "school":school,
				  "description":description},
			dataType:'text',
			async: false,
			contentType: "application/x-www-form-urlencoded; charset=utf-8",
			success:function(data){
				if(data=="success"){
					//$('.d-warning').addClass('show');
					goStep(4);
					//countLink("/scfire/project/start");	
				}
							
			},
			error: function (data){
				alert("认证信息提交失败.");
			}
		});

		
    }


    function goStep (n) {
        $('ul.step-navi > li').eq(n - 1).addClass('active').siblings().removeClass('active');
        $('.step').eq(n - 1).addClass('show').siblings().removeClass('show');
    }

    function goProject(){
    	
    }
    
	function closeDialog(element){
		$("#"+element).removeClass('show');
	}

    function countLink (url) {
        var i = 5;
        var c = null;
        $('.success-box p i').text(i);
        c = setInterval(function(){
            if (i < 1) {
                clearInterval(c);
                c = null;
                location.href = url;
            } else {
                i--;
                $('.success-box p i').text(i);
            }
        }, 1000);
    }